package elan.book.storage;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import elan.book.activity.BookCilentActivity;
import elan.book.control.constant;

public class preference {
	private BookCilentActivity instance = null;
	private SharedPreferences sp;

	public preference(BookCilentActivity instance) {
		this.instance = instance;
	}

	public boolean getPreference() {
		if (sp == null)
			sp = instance.getSharedPreferences("UserInfo",
					Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
		return true;
	}

	// save to xml
	public void saveConfig() {
		getPreference();
		sp.edit().putBoolean("firstUse", false).commit();
		sp.edit().putInt("backgroundColor", constant.backgroundColor).commit();
		sp.edit().putInt("fontColor", constant.fontColor).commit();
	}

	// get config from xml
	public boolean getConfig() {
		getPreference();
		Log.v("getConfig", "1 "+constant.firstUse);
		constant.firstUse = sp.getBoolean("firstUse", true);
		constant.backgroundColor = sp.getInt("backgroundColor", 0xffCCFFFF);
		constant.fontColor = sp.getInt("fontColor", 0xff000000);
		Log.v("getConfig", "1 "+constant.backgroundColor+" <><> "+constant.fontColor);
		return true;
	}
}
